%!TEX root = ../book.tex
\chapter{Kinematics}\label{chap:kinematics}

In order to plan a robot's movements, we have to understand the relationship between our control variables (i.e. the input to the motors that we can control at any given time) and the effect of these control variables on the motion of the robot.
The simplest models of such relationships can be built by looking at the geometry of our robot, known as the field of \textsl{kinematics}\index{Kinematics}.
For simple arms in static configurations, a kinematic model is rather straightforward: if we know the generalized position / configuration angle of each joint, we can calculate the generalized position of its end-effectors using trigonometry---a process known as \textsl{forward kinematics}\index{Forward Kinematics}.
This process is usually more involved for mobile robots, as the speeds of the wheels need to be integrated to determine changes in robot pose, which we refer to as \textsl{odometry}\index{Odometry}.
Roboticists are often concerned with trying to compute the inverse relationship: the position each joint must be at for the end-effector to be in a desired position or pose. This is generally a far more complex, underdetermined problem, known as \textsl{inverse kinematics}\index{Inverse Kinematics}.

As we will see below, kinematics is the simplest and most fundamental level of abstraction that a roboticist can use to model the motion of a robot and its geometry: it deals exclusively with positional quantities, and considers the robot as if it was frozen in time. Although this simplification is far from being realistic, we will see that a lot can be done through kinematics alone! However, a more expressive tool at our disposal is to do a similar modeling in a second level of abstraction that operates in velocity space; this domain is called \textsl{differential kinematics}\index{Differential Kinematics} and is introduced in \cref{sec:kinematics:diff}.
In all, the goals of this chapter are to:

\begin{itemize}
\item Introduce the forward kinematics of simple arms and mobile robots, and understand the concept of holonomy
\item Provide an intuition on the relationship between inverse kinematics and path-planning
\item Become familiar with differential kinematics and the Jacobian technique
\end{itemize}

Within the scope of a kinematic analysis, the term \textsl{generalized position} or \textsl{generalized configuration}\index{Generalized Position}\index{Generalized Configuration} means ``any position-equivalent quantity needed to describe the element''.
For what concerns joint space, it depends on the type of actuation: a revolute joint imparts a rotational motion around its axis and its configuration is fully described by an angle; a prismatic joint commands a translational motion along its axis and its configuration is represented by a distance.
Conversely, generalized position in task space depends on the specific task; in its most general case, a generalized position equates to the end-effector pose, which is comprised of a $3D$ position and a $3D$ orientation---as we will see below.

\begin{mdframed}
\noindent Remember:
configuration space $\equiv$ joint space;
cartesian space $\equiv$ task space.
Forward kinematics maps from joint space to task space, and inverse kinematics does the opposite.
The number of mechanical degrees-of-freedom $n$ (i.e. DoFs in task space) depends on the robot, while the number of Cartesian degrees-of-freedom $m$ (i.e. DoFs in task space) depends on the task. In general, $n \neq m$!
\end{mdframed}

%%%%%%%%%%%%%%%%%%%%
%% ACTUAL CONTENT %%
%%%%%%%%%%%%%%%%%%%%

\input{chapters/kinematics-forward}
\input{chapters/kinematics-inverse}
\input{chapters/kinematics-differential}

%%%%%%%%%%%%%%%%%%%%

\section*{Take-home lessons}

\begin{itemize}
\item Forward kinematics deals with finding a coordinate transform from a world coordinate system into a coordinate system on the robot.
Such a transform is a combination of a ($3\times1$) translation vector and a ($3\times3$) rotation matrix that consists of the unit vectors of the robot coordinate system. Both translation and rotation can be combined into a $4\times4$ homogeneous transform matrix.
\item Forward and Inverse Kinematics of a mobile robot are performed with respect to the speed of the robot and not its position.
\item To calculate the effect of each wheel on the speed of the robot, you need to consider the contribution of each wheel independently.
%\item You can then plan in configuration space of the robot using path-planning techniques.
\item The inverse kinematics of a robot involves solving the forward kinematics equations for the joint angles.
Calculating the inverse kinematics analytically becomes quickly infeasible, and is impossible for complicated mechanisms.
\item A simple numerical solution is provided by taking all partial derivatives of the forward kinematics in order to get an easily invertible expression that relates joint speeds to end-effector speeds.
\item The inverse kinematics problem can then be formulated as feedback control problem, which will move the end-effector towards its desired pose using small steps. Problems with this approach are local minima and singularities of the mechanism, which might render this solution infeasible.
\item Redundancy allows a robot to solve a kinematic problem in multiple different ways, thus providing better dexterity and versatility in its motion.
\end{itemize}

\section*{Exercises}\small
\subsection*{Coordinate systems}
\begin{enumerate}
\item
\begin{enumerate}
 \item Write out the entries of a rotation matrix $^A_BR$ assuming basis vectors $X_A$, $Y_A$, $Z_A$, and $X_B$, $Y_B$, $Z_B$.
 \item Write out the entries of rotation matrix $^B_AR$.
 \end{enumerate}
\item Assume two coordinate systems that are co-located in the same origin, but rotated around the $z-$axis by the angle $\alpha$. Derive the rotation matrix from one coordinate system into the other and verify that each entry of this matrix is indeed the scalar product of each basis vector of one coordinate system with every other basis vector in the second coordinate system.
\item Consider two coordinate systems $\{B\}$ and $\{C\}$, whose orientation is given by the rotation matrix $^C_BR$ and have distance $^BP$. Provide the homogenous transform $^C_BT$ and its inverse $^B_CT$.
\item Consider the frame $\{B\}$ that is defined with respect to frame $\{A\}$ as $\{B\}=\{^A_BR, ^AP\}$. Provide a homogeneous transform from $\{A\}$ to $\{B\}$.
\item Program a simple application that displays a 2D (or 3D) coordinate system and add the ability to move and turn the coordinate system using your keyboard.
\end{enumerate}

\subsection*{Forward and inverse kinematics}
\begin{enumerate}
\item Consider a differential wheel robot with a broken motor, i.e., one of the wheels cannot be actuated anymore. Derive the forward kinematics of this platform. Assume the right motor is broken.
\item Consider a tri-cycle with two independent standard wheels in the rear and the steerable, driven front-wheel. Choose a suitable coordinate system and use $\phi$ as the steering wheel angle and wheel-speed $\dot{\omega}$. Provide forward and inverse kinematics.
\item Program an application that displays a differential wheel platform and allows you to control forward and rotational speed with your keyboard. Output the robot's pose after every step.
\item Program an application that displays a two-link robotic arm moving in the plane and lets you change both joint angles using your keyboard.
\item Derive the forward kinematics of a two-link robotic arm as well as its Jacobian. Implement its inverse kinematic using the inverse Jacobian technique.
\item Program an application that displays a two-link robotic arm moving in the plane and lets you change the position of its end-effector using your keyboard.
\item Explore the internet for toolkits that allow you to manage forward and inverse kinematics for a robotic arm. What kind of tools do you find and what kind of input do they require to model the robot's geometry?
\item Download the manual of a commercially available robot arm of your choice. What kind of input does it take from its user? Does it allow you to control its position directly?
\item Use a robot simulator of your choice to access a simulated vehicle. What kind of actuator input can you provide and what are the sensors that are available? Drive the car using your keyboard and try to estimate its pose by implementing odometry.
\item Can you provide an example of a kinematically deficient and a kinematically redundant robot manipulator?
\end{enumerate}
\normalsize

